from django.contrib import admin
from accounts.models import *
from import_export.admin import ImportExportModelAdmin
from accounts.resource import *

admin.site.site_header = '川应后台管理系统'  # 设置路由标题
admin.site.site_title = '川应后台管理系统'  # 设置网站标题


class InfoAdmin(ImportExportModelAdmin):
    """学生信息显示"""
    # 显示字段
    list_display = ['name', 'sex', 'dept_list', 'number', 'station_list']
    # 可点击字段
    list_display_links = list_display
    # 模糊查询字段
    search_fields = ['name', 'sex', 'number']
    # 标签查询字段
    list_filter = ['dept', 'station', 'position', 'power']
    # 每页显示数量
    list_per_page = 20
    # 后台引入中文显示
    resource_class = InfoResource

    def station_list(self, obj):
        get_station = []
        for i in obj.station.all():
            get_station.append(i.name)
        return ' | '.join(get_station)

    station_list.short_description = '职位'


admin.site.register(Info, InfoAdmin)


class DeptAdmin(admin.ModelAdmin):

    list_display = ['name', 'owner', 'parent', 'label', 'status']

    list_display_links = list_display

    search_fields = ['name', 'owner']

    list_filter = ['label', 'status']

    list_per_page = 20


admin.site.register(Dept, DeptAdmin)

admin.site.register(Station)

admin.site.register(Power)

admin.site.register(Position)

admin.site.register(Label)


